package com.kolon.business.mConcise.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DecimalFormat;
import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringEscapeUtils;
import org.jdom.Document;
import org.jdom.Element;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mKolonNews.controller.MConciseSearchListController")
public class MConciseSearchListController implements SimpleController {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/business/mConcise/mConciseSearchList.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 도메인
		String url =  MsgUtil.getMessage("domain.url");
		//String url =  "http://203.225.3.188:8080"; //MsgUtil.getMessage("domain.url");
		// 세션
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String id = (String)userMap.get("userId");
		String pw = (String)userMap.get("userPw");
		//String busoCode = (String)userMap.get("DeptCode");
		String type = ComUtil.nullChk(request.getParameter("type"), "TopNews"); //TopNews , CeoInfo, Manage
		String page = ComUtil.nullChk(request.getParameter("page"), "1");
		
		Date date = new Date();
		SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
		String nDate =  simpleDate.format(date);
		
		DecimalFormat df = new DecimalFormat("00");
		Calendar cal = Calendar.getInstance();
		cal.add(cal.DATE,-7);
		String  pDate = cal.get(cal.YEAR)+"-"+df.format(cal.get(cal.MONTH)+1)+"-"+df.format(cal.get(cal.DATE));
		
		
		//검색 관련
		//String SearchTitle = request.getParameter("SearchTitle");
		//if(SearchTitle != null){
		//    SearchTitle =  new String(SearchTitle.getBytes("ISO-8859-1"),"utf-8");
	    //}
		String SearchFirst     = ComUtil.nullChk(request.getParameter("SearchFirst"));
		String SearchStartDate = ComUtil.nullChk(request.getParameter("SearchStartDate"),pDate);
		String SearchEndDate   = ComUtil.nullChk(request.getParameter("SearchEndDate"),nDate);


		
		ModelAndView modelAndView = new ModelAndView();
		
		modelAndView.addObject("type", type);	
		//modelAndView.addObject("SearchTitle", SearchTitle);
		modelAndView.addObject("SearchFirst", SearchFirst);
		modelAndView.addObject("SearchStartDate", SearchStartDate);
		modelAndView.addObject("SearchEndDate", SearchEndDate);
		
		
		
		return modelAndView;
	}

}
